package com.neulogistics.core.substation.infrastructure.persistence.repository;

import com.neulogistics.core.substation.domain.model.aggregate.TaskOrder;
import com.neulogistics.core.substation.domain.repository.ITaskOrderRepository;
import com.neulogistics.core.substation.infrastructure.persistence.converter.TaskOrderEntityPOConverter;
import com.neulogistics.core.substation.infrastructure.persistence.orm.po.TaskOrderPO;
import com.neulogistics.core.substation.infrastructure.persistence.orm.service.ITaskOrderPOService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class TaskOrderRepository implements ITaskOrderRepository {
    @Resource
    ITaskOrderPOService taskOrderPOService;

    @Override
    public void save(TaskOrder taskOrder) {
        TaskOrderPO taskOrderPO = TaskOrderEntityPOConverter.entityToPO(taskOrder);
        taskOrderPOService.saveOrUpdate(taskOrderPO);
    }

    @Override
    public TaskOrder findById(Long id) {
        TaskOrderPO taskOrderPO = taskOrderPOService.getById(id);
        TaskOrder taskOrder = TaskOrderEntityPOConverter.POToEntity(taskOrderPO);

        return taskOrder;
    }

    @Override
    public void deleteById(Long id) {
        taskOrderPOService.removeById(id);
    }
}
